package com.tarena.lbs.basic.web.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.basic.web.service.AreaService;
import com.tarena.lbs.pojo.basic.vo.AreaVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
public class AreaController {
    @Autowired
    private AreaService areaService;

    //查询省级地区列表31个
    @GetMapping("/admin/basic/area/queryList")
    public Result<List<AreaVO>> getProvinces() throws BusinessException {
        List<AreaVO> vos = areaService.getChildrenAreas(0L);
        return new Result<>(vos);
    }

    //查询下一级地区列表 可能是市区、县区、乡镇等
    @GetMapping("/admin/basic/area/{parentId}/children")
    public Result<List<AreaVO>> getChildren(@PathVariable Long parentId) throws BusinessException {
        List<AreaVO> vos = areaService.getChildrenAreas(parentId);
        return new Result<>(vos);
    }
}
